import React from "react";
import { Table, Button } from "antd";
export default function NewsPublish(props) {
  const columns = [
    {
      title: "新闻标题",
      dataIndex: "title",
      render(title, item) {
        return <a href={`#/news-manage/preview/${item.id}`}>{title}</a>;
      },
    },
    {
      title: "作者",
      dataIndex: "author",
    },
    {
      title: "新闻分类",
      dataIndex: "category",
      render(category) {
        return <div>{category.title}</div>;
      },
    },

    {
      title: "操作",
      render(item) {
        return (
          <div>
            {props.type === 1 && (
              <Button
                type="primary"
                onClick={() => {
                  props.handlePublish(item);
                }}
              >
                发布
              </Button>
            )}
            {props.type === 2 && (
              <Button
                type="primary"
                onClick={() => {
                  props.handleSunset(item);
                }}
              >
                下线
              </Button>
            )}
            {props.type === 3 && (
              <Button
                type="primary"
                danger
                onClick={() => {
                  props.handleDelet(item);
                }}
              >
                删除
              </Button>
            )}
          </div>
        );
      },
    },
  ];

  return (
    <div>
      <Table
        dataSource={props.dataSource}
        columns={columns}
        pagination="5"
        rowKey={(item) => item.id}
      />
      ;
    </div>
  );
}
